package com.wxg.demo;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import com.wxg.utils.My;
import com.wxg.utils.MyDriver;

public class ElementHeight102 {

	public static void main(String[] args) {
		code105();
	}
	
	public static void code105(){
		WebDriver driver = MyDriver.getStaticDriver();
		List<WebElement> eleList = null;
		
		String strUrl = My.fileUrl("F:\\wxg\\for_print\\html\\html104.html");
		
		driver.get( strUrl );
		eleList = driver.findElements(By.tagName("p"));
		if(null != eleList){
			System.out.println( eleList.size() );
			for(WebElement ele : eleList){
				/**
				 * xpath, id, name, tagName, className, cssSelector, linkText, partialLinkText
				 * 并不能获取到纯文本
				 */
				List<WebElement> list = ele.findElements(By.tagName("*"));
				System.out.println( list.size() );
			}
		}
		
		MyDriver.closeStaticDriver();
	}
	
	/**
	 * 测试得出的height和width与style中填写的height和width一致!
	 * 
	 */
	public static void code104(){
		WebDriver driver = MyDriver.getStaticDriver();
		String strUrl = My.fileUrl(My.rootpath("com/wxg/html/aa/onepage.html"));
		driver.get( strUrl );
		
		WebElement ele = driver.findElement(By.className("emr_main"));
		
		Point point = ele.getLocation();
		Dimension dimension = ele.getSize();
		
		System.out.println("===");
		System.out.printf( "\nx: %s, y: %s\n", point.x, point.y );
		
		System.out.println("===");
		System.out.printf( "\nheight: %s, width: %s\n", dimension.height, dimension.width );
		
		MyDriver.closeStaticDriver();
	}
	
	
	public static void code103(){
		WebDriver driver = MyDriver.getStaticDriver();
		List<WebElement> eleList = null;
		
		String strUrl = My.fileUrl("F:\\wxg\\for_print\\html\\html101.html");
		
		driver.get( strUrl );
		eleList = driver.findElements(By.tagName("p"));
		if(null != eleList){
			System.out.println( eleList.size() );
			for(WebElement ele : eleList){
				Point point = ele.getLocation();
				Dimension dimension = ele.getSize();
				System.out.printf("\nx: %s, y: %s, width: %s, height: %s\n", point.x, point.y, dimension.width, dimension.height);
			}
		}
		
		System.out.println("================");
		
		strUrl = My.fileUrl("F:\\wxg\\for_print\\html\\html102.html");
		
		driver.get( strUrl );
		eleList = driver.findElements(By.tagName("p"));
		if(null != eleList){
			System.out.println( eleList.size() );
			for(WebElement ele : eleList){
				Point point = ele.getLocation();
				Dimension dimension = ele.getSize();
				System.out.printf("\nx: %s, y: %s, width: %s, height: %s\n", point.x, point.y, dimension.width, dimension.height);
			}
		}
		
		System.out.println("================");
		
		strUrl = My.fileUrl("F:\\wxg\\for_print\\html\\html103.html");
		
		driver.get( strUrl );
		eleList = driver.findElements(By.tagName("p"));
		if(null != eleList){
			System.out.println( eleList.size() );
			for(WebElement ele : eleList){
				Point point = ele.getLocation();
				Dimension dimension = ele.getSize();
				System.out.printf("\nx: %s, y: %s, width: %s, height: %s\n", point.x, point.y, dimension.width, dimension.height);
			}
		}
		
		
		MyDriver.closeStaticDriver();
		
	}
	
	
	public static void code102(){
		File file = null;
		file = new File("F:\\wxg\\for_print\\html\\html101.html");
		
		URL url = null;
				
		try {
			url = file.toURI().toURL();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		
		WebDriver driver = MyDriver.getPhantomJSDriver();
		driver.get( url.toString() );
		List<WebElement> eleList = driver.findElements(By.tagName("p"));
		if(null != eleList){
			System.out.println( eleList.size() );
			for(WebElement ele : eleList){
				Point point = ele.getLocation();
				Dimension dimension = ele.getSize();
				System.out.printf("\n\nx: %s, y: %s, width: %s, height: %s\n", point.x, point.y, dimension.width, dimension.height);
			}
		}
		
		driver.quit();
		
	}
	
	
	public static void code101(){
		File file = null;
		file = new File("F:\\wxg\\for_print\\html\\html101.html");
		
		URL url = null;
				
		try {
			url = file.toURI().toURL();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		
		if(null != url){
			System.out.println(url.toString());
		}
		
		
	}
	
}
